# 基类
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains


class Base():
    def __init__(self, driver):
        # 双击浏览器
        self.driver = driver  # driver edge firefox chrome

    def open_url(self, url):
        self.driver.get(url)

    def find_element(self, loc):
        return self.driver.find_element(*loc)  # *: 不定长参数（解包-解括号）， loc 任意定位元素

    def send_keys(self, loc, info):  # 对元素定位进行输入操作
        self.find_element(loc).send_keys(info)

    def keys_enter(self, loc):  # 键盘回车事件
        self.find_element(loc).send_keys(Keys.ENTER)

    def keys_enter1(self, loc, info):  # 输入内容 键盘回车事件
        self.send_keys(loc, info)
        self.find_element(loc).send_keys(Keys.ENTER)

    def click(self, loc):  # 鼠标点击事件
        self.find_element(loc).click()

    def move_to_element(self, loc):  # 鼠标悬停事件
        ActionChains(self.driver).move_to_element(self.find_element(loc)).perform()


